﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BoletoElectronicoDesktop
{
    class FacturacionDAO
    {
        //inserta la venta en la bd
        public static void InsertarCompra(string PostNet, string NroTarjeta, string Fecha, string Monto)
        {

            SqlConnection connection = new SqlConnection(Funciones.connectionString);
            SqlCommand command = new SqlCommand();
            connection.Open();
            command.Connection = connection;
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.CommandText = "[SELECTASTERISCO].compra_insercion";
            command.Parameters.AddWithValue("@numero_tarjeta", NroTarjeta);
            command.Parameters.AddWithValue("@monto", Monto);
            command.Parameters.AddWithValue("@fecha", Fecha);
            command.Parameters.AddWithValue("@Postnet", PostNet);
            command.CommandTimeout = 10;
            SqlDataReader reader = command.ExecuteReader();
            DataTable dataTable = new DataTable();
            dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataTable.Load(reader);
            connection.Close();

        }

        //traigo los beneficiarios q cumplan con las busqueda
        public static DataTable ObtenerBeneficiariosHabilitados(string razon, string rubro, string calle, string num, string piso, string depto)
        {
            SqlConnection connection = new SqlConnection(Funciones.connectionString);
            SqlCommand command = new SqlCommand();
            connection.Open();
            command.Connection = connection;
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.CommandText = "[SELECTASTERISCO].[Beneficiario_Filtro]";
            if (razon != "")
                command.Parameters.AddWithValue("@razon_social", razon);
            if (calle != "")
                command.Parameters.AddWithValue("@calle", calle);
            if (num != "")
                command.Parameters.AddWithValue("@numero_calle", num);
            if (piso != "")
                command.Parameters.AddWithValue("@piso", piso);
            if (depto != "")
                command.Parameters.AddWithValue("@departamento", depto);
            if (rubro != "")
                command.Parameters.AddWithValue("@rubro_id", rubro);
            command.Parameters.AddWithValue("@habilitado", "True");
            command.CommandTimeout = 10;
            SqlDataReader reader = command.ExecuteReader();
            DataTable dataTable = new DataTable();
            dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataTable.Load(reader);
            connection.Close();
            return dataTable;
        }


        //calculos los postnet para ese beneficiario
        public static DataTable ObtenerListaPostNet(string beneficiario)
        {

            SqlConnection connection = new SqlConnection(Funciones.connectionString);
            SqlCommand command = new SqlCommand();
            connection.Open();
            command.Connection = connection;
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.CommandText = "[SELECTASTERISCO].Postnet_Filtro";
            command.Parameters.AddWithValue("@beneficiario", beneficiario);
            command.CommandTimeout = 10;
            SqlDataReader reader = command.ExecuteReader();
            DataTable dataTable = new DataTable();
            dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataTable.Load(reader);
            connection.Close();
            return dataTable;
        }




    }
}
